//
//  ZlExciseResultTableViewCell.m
//  ZLExamination
//
//  Created by Lei_Zhong_Xun on 2017/8/23.
//  Copyright © 2017年 Zheng. All rights reserved.
//

#import "ZlExciseResultTableViewCell.h"

#import "ZLExciseModel.h"

@implementation ZlExciseResultTableViewCell

- (void)setModels:(NSArray *)models {
    _models = models;
    NSLog(@"%@", models);
    [_models enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        ZLExciseResultListModel *model = (ZLExciseResultListModel *)obj;
        
        UIView *bgView = [[UIView alloc] init];
        bgView.backgroundColor = [UIColor whiteColor];
        CGFloat a = idx/5.;
        NSInteger b = idx/5+1;
        NSInteger row = a>b? b: b-1;
        
        bgView.frame = CGRectMake(kSCREEN_WIDTH/5*(idx%5), kSCREEN_WIDTH/5*row, kSCREEN_WIDTH/5, kSCREEN_WIDTH/5);
        [self.contentView addSubview:bgView];
        
        ZLExciseResultCellResultTypeStyle style = ZLExamExciseCellResultTypeStyleTrue;
        if (model.typeOfAnswer.integerValue == 1) {
            style = ZLExamExciseCellResultTypeStyleNull;
        } else if (model.typeOfAnswer.integerValue == 2) {
            style = ZLExamExciseCellResultTypeStyleTrue;
        } else {
            style = ZLExamExciseCellResultTypeStyleFalse;
        }
        
        NSLog(@"----%@",model.typeOfAnswer);
        
        UILabel *numberLbl = [self getNumberLblWithStyle:style];
        numberLbl.text = [NSString stringWithFormat:@"%ld",model.questionNumber];
        [bgView addSubview:numberLbl];
        
        [numberLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.centerY.equalTo(bgView);
            make.width.height.mas_equalTo(35);
        }];
    }];

}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

//- (void)setNumbersWithRows:(NSInteger)rows {
//    for (int i = 0; i< rows; i++) {
//        UIView *bgView = [[UIView alloc] init];
//        bgView.backgroundColor = [UIColor whiteColor];
//        CGFloat a = i/5.;
//        NSInteger b = i/5+1;
//        NSInteger row = a>b? b: b-1;
//        bgView.frame = CGRectMake(kSCREEN_WIDTH/5*(i%5), kSCREEN_WIDTH/5*row, kSCREEN_WIDTH/5, kSCREEN_WIDTH/5);
//        [self.contentView addSubview:bgView];
//        
//        UILabel *numberLbl = [self getNumberLblWithStyle:arc4random()%3];
//        numberLbl.text = [NSString stringWithFormat:@"%d",i+1];
//        [bgView addSubview:numberLbl];
//        
//        [numberLbl mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.centerX.centerY.equalTo(bgView);
//            make.width.height.mas_equalTo(35);
//        }];
//    }
//}
- (UILabel *)getNumberLblWithStyle:(ZLExciseResultCellResultTypeStyle)style {
    UILabel *numberLbl = [[UILabel alloc] init];
    numberLbl.textAlignment = NSTextAlignmentCenter;
    numberLbl.layer.cornerRadius = 17.5;
    numberLbl.layer.masksToBounds = YES;
    switch (style) {
        case ZLExamExciseCellResultTypeStyleTrue: {
            numberLbl.layer.backgroundColor = [kRGB_COLOR(237, 40, 46, 1) CGColor];
            numberLbl.textColor = [UIColor whiteColor];
        }
            break;
            
        case ZLExamExciseCellResultTypeStyleFalse: {
            numberLbl.layer.backgroundColor = [kMY_BLUE_COLOR CGColor];
            numberLbl.textColor = [UIColor whiteColor];
        }
            break;
            
        case ZLExamExciseCellResultTypeStyleNull: {
//            numberLbl.layer.backgroundColor = [[UIColor whiteColor] CGColor];
//            numberLbl.textColor = kMY_BLUE_COLOR;
//            numberLbl.layer.borderColor = [kMY_BLUE_COLOR CGColor];
//            numberLbl.layer.borderWidth = 0.5;
            numberLbl.layer.backgroundColor = [kMY_BLUE_COLOR CGColor];
            numberLbl.textColor = [UIColor whiteColor];
        }
            break;
    }
    return numberLbl;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
